/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.rh.game.loader;

import com.rh.util.Parser;

import com.rh.game.impl.ChatResponse1;
import com.rh.game.GameCondition;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author hjones
 */
public class ResponseBuffer extends AbstractXmlBuffer {
    private static void debug(Object o)  {
        // System.out.println("ResponseBuffer: " + o);
    }
    
    public ResponseBuffer()  {
        super();
        init();
    }

    private List<ChatResponse1> responses = null;
    List<ChatResponse1> getResponses()  {
        return responses;
    }
    
    void init()  {
        responses = new ArrayList<ChatResponse1>();
        init2();
    }
    
    private String text = null;
    private String next = null;
    
    void init2()  {
        text = "";
        next = "";
    }
    
    @Override
    void characters(String pValue) {
        pValue = Parser.trim(pValue);
        if (pValue.length() == 0)  return;
        
        if ("Text".equals(getStartElement()))  {
            text = pValue;
        }
        else if ("Next".equals(getStartElement()))  {
            next = pValue;
        }
    }

    @Override
    void endElement(String pName)  {
        if ("response".equals(pName))  {
            ChatResponse1 cr = new ChatResponse1(text, next, GameCondition.NULL);
            responses.add(cr);
            init2();
        }
    }
}
